package router

import (
	"blog/api"
	"blog/asset"
	"blog/context"
	"blog/views"
	"net/http"

	assetfs "github.com/elazarl/go-bindata-assetfs"
)

func Router() {
	fs := assetfs.AssetFS{
		Asset:    asset.Asset,
		AssetDir: asset.AssetDir,
	}
	http.Handle("/", context.Context)
	context.Context.Handler("/", views.HTML.Index)
	context.Context.Handler("/login", views.HTML.Login)
	context.Context.Handler("/c/{id}", views.HTML.Category)
	context.Context.Handler("/p/{pId}.html", views.HTML.Detail)
	context.Context.Handler("/writing", views.HTML.Writing)
	context.Context.Handler("/pigeonhole", views.HTML.Pigeonhole)
	context.Context.Handler("/api/v1/post", api.API.SaveAndUpdateAndGetPostAndDeletePost)
	context.Context.Handler("/api/v1/post/{pId}", api.API.SaveAndUpdateAndGetPostAndDeletePost)
	context.Context.Handler("/api/v1/post/search", api.API.SearchPost)
	context.Context.Handler("/api/v1/qiniu/token", api.API.QiniuToken)
	context.Context.Handler("/api/v1/login", api.API.Login)

	// http.HandleFunc("/", views.HTML.Index)
	// http.HandleFunc("/login", views.HTML.Login)
	// http.HandleFunc("/c/", views.HTML.Category)
	// http.HandleFunc("/p/", views.HTML.Detail)
	// http.HandleFunc("/writing", views.HTML.Writing)
	// http.HandleFunc("/pigeonhole", views.HTML.Pigeonhole)
	// http.HandleFunc("/api/v1/post", api.API.SaveAndUpdateAndGetPost)
	// http.HandleFunc("/api/v1/post/", api.API.SaveAndUpdateAndGetPost)
	// http.HandleFunc("/api/v1/post/search", api.API.SearchPost)
	// http.HandleFunc("/api/v1/qiniu/token", api.API.QiniuToken)
	// http.HandleFunc("/api/v1/login", api.API.Login)
	//http.Handle("/resource/", http.StripPrefix("/resource/", http.FileServer(http.Dir("public/resource/"))))
	http.Handle("/resource/", http.FileServer(&fs))
}
